home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / msgval / msgstrip.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.5 KB  |  113 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. char msgbase[200];
  6.  
  7. struct MailHeader {
  8.     char    Status[1];
  9.     long    MsgNumb;
  10.     char    ToName[31],
  11.         FromName[31],
  12.         Subject[31];
  13.     long    MsgDate,
  14.         Recv;
  15.     char Pad;
  16.     };
  17. void sr(char *s);
  18.  
  19. main(int argc,char *argv[])
  20. {
  21.   int i;
  22.   FILE *fi;
  23.   int lost=0;
  24.   int remit=0;
  25.   ULONG Position;
  26.   struct MailHeader t;
  27.   char headername[200];
  28.   char filename[200];
  29.   if(argc<2)
  30.   {
  31.     printf("\n");
  32.     printf(" .--------------------------------------------------------.\n");
  33.     printf(" | Ami-Express MsgStrip Version 1.1 Written by ByteMaster |\n");
  34.     printf(" |       /X Development Team - The Silent Achievers       |\n");
  35.     printf(" `--------------------------------------------------------'\n");
  36.     printf("\n");
  37.     printf("usage: MsgStrip <msgbase directory> \n");
  38.     printf("   ie: MsgStrip BBS:PD/msgbase\n");
  39.     printf("\n");
  40.     exit(0);
  41.   }
  42.   if(argc==3) remit=1;
  43.  
  44.   printf("\n");
  45.   printf(" .--------------------------------------------------------.\n");
  46.   printf(" | Ami-Express MsgStrip Version 1.1 Written by ByteMaster |\n");
  47.   printf(" |      /X Development Team - The Silent Achievers        |\n");
  48.   printf(" `--------------------------------------------------------'\n");
  49.   printf("\n");
  50.  
  51.   strcpy(msgbase,argv[1]);
  52.   
  53.   
  54.   sr(msgbase);
  55.   
  56.   i=strlen(msgbase)-1;
  57.   if(msgbase[i]!=':' && msgbase[i]!='/') strcat(msgbase,"/");
  58.   
  59.   sprintf(headername,"%sheaderfile",msgbase);
  60.   
  61.   Position=0L;
  62.   
  63.   fi=fopen(headername,"r+b");
  64.   
  65.   if(fi==NULL)
  66.   {
  67.     printf("\n");
  68.     printf("Error, can't locate msgbase\n");
  69.     printf("\n");
  70.     exit(0);
  71.   }
  72.   
  73.   printf("\n");
  74.   printf("\n");
  75.   printf("Scanning Message Base for received messages\n\n");
  76.   
  77.   while(fread((APTR)&t,sizeof(struct MailHeader),1,fi)!=NULL)
  78.   {
  79.   
  80.     if(t.Status[0]=='R' && t.Recv!=0)
  81.     {
  82.       sprintf(filename,"%s%d",msgbase,t.MsgNumb);
  83.       if(!access(filename,00))
  84.       {
  85.         printf("Received , Msg number # %ld\n",t.MsgNumb);
  86.         t.Status[0]='D';
  87.         if(remit) { fseek(fi,Position,0L); fwrite((APTR)&t,sizeof(struct MailHeader),1,fi); 
  88.                     fseek(fi,Position,0L); }
  89.         lost +=1;
  90.         DeleteFile(filename);
  91.       }
  92.     
  93.     }
  94.     Position=ftell(fi);
  95.   }
  96.   fclose(fi);
  97.   if(lost)printf("Total Received messages = %d\n",lost);
  98.   else
  99.   printf("MsgVal reports no lost messages\n\n");
  100.   exit(0);
  101. }
  102.  
  103. void sr(char *s)
  104. {
  105.   register int i;
  106.   i=strlen(s)-1;
  107.   while(i>-1)
  108.   {
  109.     if(*(s+i)<=32) *(s+i)='\0'; else break;
  110.     i--;
  111.   }
  112. }
  113.